Skip to content

Conversation

sgaist
Copy link
Contributor

@sgaist sgaist commented Oct 7, 2025

Add a warning when pytest.ini and pyproject.toml are present

The behaviour does not change however users will be notified that pytest.ini is selected over pyproject.toml and any configuration related to pytest it may contain.

Fixes #13330

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 7, 2025
@sgaist sgaist force-pushed the add-warning-on-pytest-ini-and-pyproject-presence branch from caf5ef7 to fce5184 Compare October 7, 2025 19:15
The behaviour does not change however users will be notified that
pytest.ini is selected over pyproject.toml and any configuration
related to pytest it may contain.
@sgaist sgaist force-pushed the add-warning-on-pytest-ini-and-pyproject-presence branch from fce5184 to 5ff1af4 Compare October 7, 2025 19:29
@sgaist
Copy link
Contributor Author

sgaist commented Oct 7, 2025

I am unsure what to do to satisfy codecov. Any hint would be appreciated.

Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this.

I haven't thought yet whether we really want this, but in any case a couple of comments:

We should not emit a warning if pyproject.toml exists but without a pytest section. That's very common and expected and not ambiguous (please also add a test for this case).

Also, it will be better not to have the "should warn" logic in terminal.py, it shouldn't know about config stuff itself. Ideally (I think) the core config file search logic should indicate whether need to warn.

Doing so, Terminal does not need to know anything about
the configuration files.
@sgaist
Copy link
Contributor Author

sgaist commented Oct 7, 2025

@bluetech I should have kept my original implementation which was following your suggestion minus the verification of the content of the pyproject.toml file.

I refactored the code following your suggestion.

@sgaist sgaist requested a review from bluetech October 7, 2025 21:16
Do it the other way around, check if the file suffix is ini
rather than listing the possible names.
return self._inipath

@property
def should_warn(self) -> bool:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update.

  • We shouldn't expose this in the public API, let's keep it private unless there's a need.

  • If it's private, no need for a property

  • The name should_warn is too generic, we should say warn about what. Or better, something like _ignored_config_files = ["pyproject.toml", ".pytest.ini'] containing the ignored files we detected. Semantically whether or not to warn is up to the place which warns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me, I'll update the code.

This will let users know exactly which files have
been ignored in case multiple of them contain pytest
configuration.
Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Now the approach looks good to me, though I haven't reviewed the code in detail.

@nicoddemus I'll leave it to you to decide whether we want this :)

args, namespace=copy.copy(self.option)
)
rootpath, inipath, inicfg = determine_setup(
rootpath, inipath, inicfg, ignored_files = determine_setup(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use ignored_config_files because ignored_files as again a bit too generic.

@nicoddemus
Copy link
Member

@nicoddemus I'll leave it to you to decide whether we want this :)

I think so, because having both configurations is confusing and error prone -- a warning would be welcome.

I will try to review this in the next few days, thanks folks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided (automation) changelog entry is part of PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn if both pytest.ini (.pytest.ini) and pyproject.toml with pytest ops exist
3 participants